#include <cstdio>
#include <cstring>

const int Limit_Size = 50000;

char bstr[ Limit_Size ], tstr[ Limit_Size ];
int n, bonus[ 800 ], opt[ Limit_Size ], l1, l2;

void init( )
{
    int i;
    char t[ Limit_Size ];
    scanf("%s", t);
    for ( i = 0; i < n; i++ )
        scanf("%d", &bonus[ t[ i ] ]);
    scanf("%s%s", tstr, bstr);
    l1 = strlen( tstr );
    l2 = strlen( bstr );
    for ( i = 0; i < l2; i++ )
        opt[ i ] = 0;
}

void work( )
{
    int i, j, k, t;
    for ( i = 0; i < l1; i++ )
    {
        for ( j = l2 - 1; j >= 0; j-- )
        {
            if ( bstr[ j ] == tstr[ i ] )
            {
                if ( j > 0 )
                    t = opt[ j - 1 ] + bonus[ bstr[ j ] ];
                else
                    t = bonus[ bstr[ j ] ];
                for ( k = j; k < l2; k++ )
                {
                    if ( opt[ k ] >= t )
                        break;
                    opt[ k ] = t;
                }
            }
        }
    }
}

void print( )
{
    printf("%d\n", opt[ l2 - 1 ]);
}

int main( )
{
    while ( scanf("%d", &n) != EOF )
    {
        init( );
        work( );
        print( );
    }
    return 0;
}

